/**
 * 
 */
package com.firebird.oms.web.dwr.sm;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import com.firebird.base.domain.Page;
import com.firebird.oms.domain.sm.TismFunction;
import com.firebird.oms.domain.sm.TismMenu;
import com.firebird.oms.service.sm.AuthService;
import com.firebird.oms.web.base.BaseDwr;

/**
 * @author qiuxj
 * @date 2009-11-24
 *
 */
public class FunctionDwr extends BaseDwr {
	
	private AuthService authService;

	/**
	 * 取得权限方法
	 * 
	 * @param funcId
	 * @return
	 */
	public TismFunction getTismFunction(int funcId) {
		return authService.getTismFunction(funcId);
	}

	/**
	 * 取得权限及其关联的菜单
	 * 
	 * @param funcId
	 * @return
	 */
	public TismFunction getTismFunctionAndExt(int funcId) {
		return authService.getTismFunctionAndExt(funcId);
	}

	/**
	 * 创建权限方法
	 * 
	 * @param smFunction
	 * @return
	 */
	public Serializable createFunction(TismFunction smFunction) {
		return authService.createFunction(smFunction);
	}

	/**
	 * 更新权限方法
	 * 
	 * @param smFunction
	 */
	public void updateFunction(TismFunction smFunction) {
		smFunction.setMenus(authService.getTismFunctionAndExt(smFunction.getFuncId()).getMenus());
		authService.updateFunction(smFunction);
	}

	/**
	 * 更新权限及其关联菜单方法
	 * 
	 * @param funcId
	 * @param menus
	 */
	public void updateFunctionAndExt(int funcId, List<TismMenu> menus) {
		TismFunction smFunction = authService.getTismFunction(funcId);
		smFunction.setMenus(new HashSet<TismMenu>(menus));
		authService.updateFunction(smFunction);
	}

	/**
	 * 分页查询权限方法
	 * 
	 * @param filter
	 * @param likeMap
	 * @param sortMap
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	public Page pageFunction(Map<String, String> filter, Map<String, String> likeMap, Map<String, String> sortMap,
			int pageNo, int pageSize) {
		return authService.pageFunction(filter, likeMap, sortMap, pageNo, pageSize);
	}

	/**
	 * 查询权限列表方法
	 * 
	 * @param filter
	 * @return
	 */
	public List<TismFunction> findTismFunctions(Map<String, String> filter) {
		return authService.findTismFunctions(filter);
	}

	public void setAuthService(AuthService authService) {
		this.authService = authService;
	}

}
